<div id="secondary" class="content">
<h3>Om Ironman.no</h3>
<p class="about"><?php bloginfo('description'); ?></p>

<?php
function getBestTime($sex=0) {
	global $wpdb;   // Give wpdb with global scope
	$sql = "SELECT record.id, record.timetotal, record.year, competition.name as competition, athlete.name as athlete 
		FROM record 
		left join athlete on record.athlete_id = athlete.id 
		left join competition on record.competition_id = competition.id 
		WHERE athlete.sex = $sex AND record.timetotal != ''
		order by record.timetotal ASC 
		limit 5"; 
	return $wpdb->get_results($sql);
}
$results_men = getBestTime(0);
$results_women = getBestTime(1);
?>
<h3>5 beste menn gjennom tidene</h3>
<ol class="top-athletes top-athletes-men">
<?php foreach($results_men as $result): ?>
	<li><a href="<?php bloginfo('url') ?>/resultater/?query=<?php echo $result->athlete; ?>" title="<?php echo $result->athlete; ?> brukte <?php echo $result->timetotal; ?> i <?php echo $result->competition; ?>, <?php echo $result->year; ?>">
		<?php echo $result->athlete; ?></a> <span><?php echo $result->timetotal; ?></span></li>
<?php endforeach; ?>
</ol>
<h3>5 beste kvinner gjennom tidene</h3>
<ol class="top-athletes top-athletes-women">
<?php foreach($results_women as $result): ?>
	<li><a href="<?php bloginfo('url') ?>/resultater/?query=<?php echo $result->athlete; ?>" title="<?php echo $result->athlete; ?> brukte <?php echo $result->timetotal; ?> i <?php echo $result->competition; ?>, <?php echo $result->year; ?>">
		<?php echo $result->athlete; ?></a> <span><?php echo $result->timetotal; ?></span></li>
<?php endforeach; ?>
</ol>
<h3>Sponsor:</h3>
<p><a href="http://www.fusion.dk" target="_blank" rel="sponsor" class="fusion">
<img src="<?php bloginfo('template_directory'); ?>/images/sponsor/fusion.gif" alt="Fusion sportsutstyr" title="Gå til www.fusion.dk" /></a></p>
<h3>Utviklet av:</h3>
<p><a href="http://www.gersh.no" target="_blank" rel="developer" class="gersh">
<img src="<?php bloginfo('template_directory'); ?>/images/sponsor/gersh.gif" alt="Gerhard Sletten alias Gersh" title="Gå til www.gersh.no" /></a></p>
</p>
</div><!-- end content_extra -->